<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/echarts.min.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="js/ol.css">
    <script src="js/ol-debug.js"></script>

</head>
<body>
<div id="map" style="width: 100%"></div>
<script>
    var mapKey="5511da246effc06002661c77fea80ba1";
    //view
    var view=new ol.View({
        // 设置成都为地图中心
        center: ol.proj.transform([110,39],"EPSG:4326","EPSG:3857"),
        zoom: 4
    });
    //var osm=new ol.layer.Tile({source: new ol.source.OSM()});
    // map
    var map = new ol.Map({
        // layers: [
        //     getTdtLayer("vec_w"),
        //     getTdtLayer("cva_w"),
        //
        // ],
        layers: [TiandiMap_vec,TiandiMap_cva,TiandiMap_img,TiandiMap_cia],
        view:view,
        target: 'map'
    });

    function getTdtLayer(lyr) {
        var urls=[];
        for(var i=0;i<8;i++)
        {
            urls.push( "http://t"+i+".tianditu.com/DataServer?T=" + lyr + "&X={x}&Y={y}&L={z}")
        }
        var layer = new ol.layer.Tile({
            source: new ol.source.XYZ({
                urls:urls
            })
        });
        return layer;
    }

    var TiandiMap_vec = new TileLayer({
        name: "天地图矢量图层",
        source: new XYZ({
            url:
                "http://t0.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=" +
                mapkey, //mapkey为天地图密钥
            wrapX: false,
        }),
    });
    var TiandiMap_cva = new TileLayer({
        name: "天地图矢量注记图层",
        source: new XYZ({
            url:
                "http://t0.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=" +
                mapkey, //mapkey为天地图密钥
            wrapX: false,
        }),
    });
    var TiandiMap_img = new TileLayer({
        name: "天地图影像图层",
        source: new XYZ({
            url:
                "http://t0.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=" +
                mapkey, //mapkey为天地图密钥
            wrapX: false,
        }),
    });
    var TiandiMap_cia = new TileLayer({
        name: "天地图影像注记图层",
        source: new XYZ({
            url:
                "http://t0.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=" +
                mapkey, //mapkey为天地图密钥
            wrapX: false,
        }),
    });

</script>
</body>
</html>
